<?php
	defined('_JEXEC') or die('Restricted access');
   	require_once("query_parameters_class.php");
	//
	// t_base_component
	//
	
	class t_query_repository
	{
		// property declaration
		// public
		// D
		const query_parameter_name = "query_parameter";
		const query_field_name = "query_db_field";
		const query_position_of_value_name = "query_value_position";
		// R
		public $repository = array(); 
		// method declaration
		// public
		// D
        public function disconnect_all_db_connections($a_ignore_mysql_close = false)        
        {
			foreach ($this->repository as $local_repository_name => $local_repository) 
			{
				$local_repository[self::query_parameter_name]->close_connection($a_ignore_mysql_close);
			}
		}		
		// G
		public function get_query($a_query_repository_name)
		{
			//echo "a_query_repository_name: $a_query_repository_name; <br>" ;
            //print_r($this->repository[$a_query_repository_name]);
            //echo "<br>";
            return $this->repository[$a_query_repository_name][self::query_parameter_name];
		}
		public function get_repository_item($a_query_repository_name)
		{
			return $this->repository[$a_query_repository_name];
		}		
		// N
		public function new_query($a_query_repository_name,$a_sql_query,$a_connection = null,$a_parent_component_class = '')
		{
			//echo "a_query_repository_name: $a_query_repository_name - a_sql_query: $a_sql_query";
            $this->repository[$a_query_repository_name][self::query_parameter_name] = new t_query_parameter($a_sql_query,$a_connection,
				$a_parent_component_class);
			return $this->get_query($a_query_repository_name);
		}
		public function new_query_parameter($a_query_repository_name,$a_param_name,$a_query_field,$a_query_position_of_value)
		{
			$this->repository[$a_query_repository_name][$a_param_name][self::query_field_name] = $a_query_field;
			$this->repository[$a_query_repository_name][$a_param_name][self::query_position_of_value_name] = $a_query_position_of_value;
		}
        // Q
        public function query_field($a_query_repository_name,$a_query_field_name)
        {
			return $this->get_query($a_query_repository_name)->get_field_value(
				$a_query_field_name);
        }
        public function query_param($a_query_repository_name,$query_parameter_name)
        {

            $local_query_field = $this->repository[$a_query_repository_name][$query_parameter_name][self::query_field_name]; 
			//echo "local_query_field: $local_query_field; <br>" ;
			$local_position_of_value = $this->repository[$a_query_repository_name][$query_parameter_name][self::query_position_of_value_name];
		//	echo "local_position_of_value: $local_position_of_value;" ;
			return $this->get_query($a_query_repository_name)->get_parameter_value(
				$local_query_field,$local_position_of_value);
        }		
	}

?>	